#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org

START=99



start() {

ps > /tmp/1.ds18
sleep 1
grep -q ds18b20 /tmp/1.ds18
if [ $? -eq 1 ]; then
 dserr18=$(awk -F" " '/dserr18/ {print $1}' /tmp/1.ds18)
 ds18b20=$(awk -F" " '/ds18b20/ {print $1}' /tmp/1.ds18)
 kill $dserr18 &>/dev/null
 kill $ds18b20 &>/dev/null
fi
 rm /tmp/1.ds18
 cp -f /usr/bin/tstatgpio.html /tmp/
 ds18b20 &
 dserr18 &

}

stop() {

	rm /tmp/zawis.gp &> /dev/null
	rm /etc/config/.ds18* &> /dev/null

	rm /tmp/d_x &> /dev/null
	rm /tmp/shrzs &> /dev/null
	rm /tmp/tstatgpio.html &> /dev/null
	rm /tmp/ds18b20 &> /dev/null
	rm /tmp/gpiotemp &> /dev/null
	rm /tmp/thermgpio &> /dev/null
	rm /tmp/log/narodgpiomon.log2 &> /dev/null
	rm /tmp/log/narodgpiomon_all &> /dev/null
	rm /var/zawis.gp &> /dev/null

				trmst=0
			while [ "$trmst" -ne  "10" ]; do
				ertf=$(sed -e '/./{H;$!d;}' -e 'x;/ds18b20_s'$trmst'/!d;/pwout/!d' /etc/config/ds18b20 | sed -n '/pwout/p' | awk '{print $3}'); ertf1=$(echo "${ertf} = ${#ertf}" | awk '{print $3}'); ertf12=$(echo $(( ${ertf1} - 2 )))
				gp_conf=$(echo ${ertf:1:$ertf12})
				echo 0 > /sys/class/gpio/gpio"$gp_conf"/value
				rm /tmp/log/narodmon.Dev"$trmst" &> /dev/null
				: $((trmst = $trmst + 1))
			done
ps > /tmp/1.ds18
dserr18=$(awk -F" " '/dserr18/ {print $1}' /tmp/1.ds18)
ds18b20=$(awk -F" " '/ds18b20/ {print $1}' /tmp/1.ds18)
kill $dserr18 &>/dev/null
kill $ds18b20 &>/dev/null
rm /tmp/1.ds18
}

